<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">选择时间:</label>
        <div class="col-xs-12 col-sm-8">
            <input data-rule="required" id="date_range" type="text" class="form-control datetimerange" data-time-picker="false" placeholder="选择时间" name="row[date_range]" date-show-dropdowns="true" value="" autocomplete="off" /> 
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">分发渠道:</label>
        <div class="col-xs-12 col-sm-8">
            
            <div class="radio">
            {foreach name="channel" item="vo"}
            <label for="row[channel]-{$key}"><input id="row[channel]-{$key}" name="row[channel]" type="radio" value="{$vo.id}" /> {$vo.name}</label> 
            {/foreach}
            </div>

        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <input type="button" id="search" name="button" value="{:__('OK')}" class="btn btn-success btn-embossed">
        </div>
    </div>
</form>
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
    $('#search').click(function () {
        var date_range=$('#date_range').val()
        if (date_range.length==0) {
            alert('请选择时间')
        }
        var channel = $('input[type="radio"]:checked').val();
        console.log($('input[type="radio"]:checked'))
        $.ajax({
            url: "shops/repetitive/add",
            type: 'post',
            dataType: 'json',
            data: {date: date_range,channel:channel},
            success: function (ret) {
                if (ret.code==0) {
                    alert(ret.msg)
                } else {
                    console.log(ret.data)
                    if (ret.data.length>0) {
                        var text = ''
                        for (var i = ret.data.length - 1; i >= 0; i--) {
                            text += ret.data[i]+'\r\n'
                        }
                        copyToClipboard_js(text)
                        alert('消息已复制到剪贴板，可直接粘贴')
                    } else {
                        alert('没有可以复制的消息')
                    }
                }
            }, error: function (e) {
                alert('请求出错');
            }
        });
    })
    function copyToClipboard_js(txt) {
        var temp = document.createElement("textarea"); //声明创建一个input元素
        document.body.appendChild(temp); //在body中追加input元素
        temp.value = txt; //把要复制的文字赋予input元素
        temp.select(); //选择要复制的文字
        document.execCommand("copy"); //把文字复制到剪贴板
        document.body.removeChild(temp); //移除body追加的input元素
    }
</script>
